

package jetbrains.buildServer.server.rest.model.changeLog;

import java.util.List;
import java.util.stream.Collectors;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
import jetbrains.buildServer.controllers.buildType.tabs.GraphCommit;

@XmlType(name = "changeLogGraphChangeVertex")
public class ChangeLogGraphChangeVertex extends ChangeLogGraphVertex<GraphCommit> {
  public ChangeLogGraphChangeVertex(GraphCommit vertex) {
    super(vertex);
  }

  @XmlAttribute(name = "last")
  public Boolean getLast() {
    if(getVertex().isLastInRange()) {
      return true;
    }

    // For now we just stick to the format of the old graph, hence null instead of false.
    return null;
  }

  @XmlElement(name = "subrepos")
  public List<ChangeLogGraphSubrepoChange> getSubrepoChanges() {
    List<ChangeLogGraphSubrepoChange> result = getVertex().getSubrepoChanges().stream().map(ChangeLogGraphSubrepoChange::new).collect(Collectors.toList());
    if(!result.isEmpty()) {
      return result;
    }

    return null;
  }
}